package com.zzw.service.impl;

import com.zzw.entity.Brand;
import com.zzw.mapper.BrandMapper;
import com.zzw.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Project: warehouse
 * @Description:
 * @Author: zzw
 */
// 指定缓存名称即键的前缀，一般是@CacheConfig标注的类的全类名
@CacheConfig(cacheNames = "com.zzw.service.impl.BrandServiceImpl")
@Service
@Slf4j
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    // 对查询到的所有品牌进行缓存,缓存到redis的键为all:brand
    @Cacheable(key = "'all:brand'")
    @Override
    public List<Brand> queryAllBrand() {
        // 查询所有品牌
        return brandMapper.findAllBrand();
    }
}
